import urllib.request
import urllib.parse
import ssl
def usercheck(id_card,real_name):
    # 阿里云的api地址
    host = 'https://zidv2.market.alicloudapi.com'
    # 请求路径
    path = '/idcheck/Post'
    # 请求方法
    method = 'POST'
    # 自己的appcode,在控制台可以获取的到·
    appcode = 'c541727433b743838b0273d31b0d70c3'
    querys = ''
    bodys = {}
    url = host + path
    # 接受参数
    bodys['cardNo'] = id_card
    bodys['realName'] = real_name
    # 进行urllib 的一个路径编码方式
    post_data = urllib.parse.urlencode(bodys).encode('utf-8')

    request = urllib.request.Request(url, data=post_data, method=method)
    request.add_header('Authorization', 'APPCODE ' + appcode)
    # 根据API的要求，定义相对应的Content-Type
    request.add_header('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
    # 创建一个默认的SSL上下文对象ctx，该对象包含用于处理SSL连接的配置信息。
    ctx = ssl.create_default_context()
     # 将ctx的check_hostname属性设置为False，表示在连接期间不验证服务器的主机名。
    ctx.check_hostname = False
    # 4. 使用urllib库的urlopen函数打开一个URL请求，并将上下文对象ctx作为参数传递给该函数，返回一个响应对象response
    ctx.verify_mode = ssl.CERT_NONE
    # 发送HTTPS请求时，禁用SSL证书验证和主机名验证，以避免证书错误或警告，并获取返回的内容
    response = urllib.request.urlopen(request, context=ctx)
    content = response.read().decode('utf-8')
    return content


import urllib.request, sys
import ssl

def user_check(id_card,real_name):
    host = 'https://idenauthen.market.alicloudapi.com'
    path = '/idenAuthentication'
    method = 'POST'
    appcode = 'c541727433b743838b0273d31b0d70c3'
    querys = ''
    bodys = {}
    url = host + path
    bodys['idNo'] = id_card
    bodys['name'] = real_name
    post_data = urllib.parse.urlencode(bodys)
    request = urllib.request.Request(url, data=post_data.encode('utf-8'))
    request.add_header('Authorization', 'APPCODE ' + appcode)
    # //根据API的要求，定义相对应的Content-Type
    request.add_header('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
    ctx = ssl.create_default_context()
    ctx.check_hostname = False
    ctx.verify_mode = ssl.CERT_NONE
    response = urllib.request.urlopen(request, context=ctx)
    content = response.read().decode('utf-8')
    return content